import 'package:earclean/app/config/colors.dart';
import 'package:earclean/app/modules/widget/app_bar_widget.dart';
import 'package:earclean/app/modules/widget/login_button.dart';
import 'package:earclean/app/modules/widget/login_input.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/user_info_controller.dart';

class UserInfoView extends GetView<UserInfoController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const AppBarWidget(titleStr: '修改个人资料'),
      body: Column(
        children: [
          Container(
            height: 100,
            margin: EdgeInsets.symmetric(horizontal: 18, vertical: 10),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(10.r)),
            ),
            child: Column(
              children: [
                Expanded(
                  child: InkWell(
                    onTap: () {
                      EasyLoading.showToast('头像半年修改一次');
                    },
                    child: Container(
                      padding: const EdgeInsets.symmetric(horizontal: 12),
                      child: Row(
                        children: [
                          Text('头像',
                              style: const TextStyle(
                                  fontSize: 13, color: ColorConfig.text_label)),
                          Spacer(),
                          ClipOval(
                            child: Image.asset(
                              'assets/images/组 35@2x.png',
                              width: 30,
                              height: 30,
                              fit: BoxFit.cover,
                            ),
                          ),
                          SizedBox(width: 5),
                          Icon(
                            Icons.chevron_right,
                            size: 20,
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
                Container(
                    height: 1,
                    width: 1.sw,
                    color: ColorConfig.diver_color.withAlpha(19),
                    margin: EdgeInsets.symmetric(horizontal: 10)),
                Expanded(
                  child: Container(
                    width: 1.sw,
                    padding: const EdgeInsets.symmetric(horizontal: 12),
                    child: Row(
                      children: [
                        Container(
                          width: 100,
                          child: Text('昵称',
                              style: const TextStyle(
                                  fontSize: 13, color: ColorConfig.text_label)),
                        ),
                        SizedBox(width: 5),
                        Spacer(),
                        Container(
                          width: 100,
                          child: Obx(() => LoginInput(
                                hint: "请输入昵称",
                                autofocus: true,
                                defaulTiele: controller.name.value,
                                keyBoardType: TextInputType.name,
                                inputFormatters: [
                                  LengthLimitingTextInputFormatter(5)
                                ],
                                onChanged: (text) {
                                  controller.nameStr = text;
                                },
                              )),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
          Spacer(),
          Container(
            width: 1.sw,
            height: 45,
            margin: EdgeInsets.symmetric(horizontal: 30.w),
            child: LoginButton(
              "确定",
              enable: true,
              onPressed: () {
                controller.save();
              },
            ),
          ),
          SizedBox(height: 30)
        ],
      ),
    );
  }

  Container inputWidget(String text, BuildContext context,
      {bool obscureText = false}) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 27.5.w),
      child: Row(
        children: [
          Container(
              child: Text(text,
                  style: TextStyle(
                      color: ColorConfig.subtitle_text, fontSize: 16.sp))),
          Expanded(
            child: TextField(
              obscureText: obscureText,
              inputFormatters: [
                FilteringTextInputFormatter.singleLineFormatter,
                LengthLimitingTextInputFormatter(18)
              ],
            ),
          ),
        ],
      ),
    );
  }
}
